extern "C" {
#include "map.h"
}

#define log(...) {printf(__VA_ARGS__); printf("\n");}
#include <sys/timeb.h>
void valueDeleteCallback(void *key, void *value) {
	printf("delete value\n");
}

//#define _test_map_
#ifdef _test_map_
int main(void) {

	int voidprtSize = sizeof(void*);
	log("void * size = %d", voidprtSize);

	void *map = if_map_new(-1, true, valueDeleteCallback);
	char *k1 = (char*)"k1k1k1";
	int v1 = 18;
	char *k2 = (char*)"1231231231231";
	char *v2 = (char*)"v2v2v2v2v2";
	char *k3 = (char*)"k1k1k1";
	int v3 = 899;
	char *k4 = (char*)"k1k11k";
	int v4 = 44444;
	char *k5 = (char*)"1k1k1k";
	char *v5 = (char*)"v5v5v5v5v5v5";

	char *k6 = (char*)"1k1k1k11";
	if_map_put(map, k1, &v1);
	if_map_put(map, k2, v2);
	if_map_put(map, k4, &v4);
	if_map_put(map, k5, v5);
	void *outvalue = if_map_put(map, k3, &v3);

	if (outvalue) {
		log("outvalue=%d", *((int*)outvalue));
	}

	void *get1ptr = if_map_get(map, (char*)"123123123123");
	void *get2ptr = if_map_get(map, k2);
	char *get2 = NULL;
	int get1  = 0;
	if (get1ptr) {
		 get1 = *((int*)get1ptr);
	}
	BOOL has = if_map_has(map, k1);
	BOOL contain = if_map_contain(map, v2);
	if (get2ptr) {
		get2 = (char*)get2ptr;
	}
	int size = if_map_size(map);
	void *getv5ptr = if_map_get(map, k5);
	char *getv5 = NULL;
	if (getv5ptr) {
		getv5 = (char*)getv5ptr;
	}

	void *v6 = if_map_get(map, k6);
	log("get1=%d, has=%d, contain=%d, get2=%s, get5=%s, size=%d, v6=%d", get1, has, contain, get2, getv5, size, v6);

	void **rets = if_map_values(map);
	int i = 0;
	while(i < size) {
		log("i = %d, *rets=%s, *rets=%d", i, rets[i], rets[i]);
		i++;
	}

	get1 = 0;
	size = if_map_size(map);
	get1ptr = if_map_remove(map, k1);
	if (get1ptr) {
		 get1 = *((int*)get1ptr);
	}
	log("get1=%d, size=%d", get1, size);

	size = if_map_size(map);
	log("size=%d", size);

	if_map_removeValue(map, v5); 
	size = if_map_size(map);
	log("size=%d", size);

	if_map_clear(map);
	size = if_map_size(map);
	log("size=%d", size);

	struct timeb tb;
	struct timeb tb1;
	ftime(&tb);
	for (int i = 0; i < 10000000; i++) {
		char key[128] = {0};
		sprintf(key, "key_%d", i);
		char *value = (char*) malloc(128 * sizeof(char));
		sprintf(value, "value_%d", i);
		if_map_put(map, key, value);
	}
	ftime(&tb1);
	printf("end t1 = %ld.%d", tb.time);
	printf(" end t2 = %ld\n", tb1.time);
	double delta = (tb1.time - tb.time) + (tb1.millitm - tb.millitm) / 1000.0;
	printf("put time = %lf\n", delta);
	size = if_map_size(map);
	log("size=%d", size);

	ftime(&tb);
	for (int i = 0; i < 10000000; i++) {
		char key[128] = {0};
		sprintf(key, "key_%d", i);
		char * value = (char*)if_map_get(map, key);
		//printf("value=%s ", value);
	}
	ftime(&tb1);
	printf("end t1 = %ld.%d", tb.time);
	printf(" end t2 = %ld\n", tb1.time);
	delta = (tb1.time - tb.time) + (tb1.millitm - tb.millitm) / 1000.0;
	printf("get time = %lf\n", delta);

	getchar();
}
#endif